package demoxsgl_300.com.gouwu1500.zhi;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.lang.ref.WeakReference;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import demoxsgl_300.com.gouwu1500.R;
import demoxsgl_300.com.gouwu1500.certificateCamera.CameraActivity;


public class GeRenActivity extends Activity {

    @BindView(R.id.textView5)
    TextView textView5;
    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.nan)
    ImageView nan;
    @BindView(R.id.tv_nan)
    TextView tvNan;
    @BindView(R.id.nv)
    ImageView nv;
    @BindView(R.id.tv_nv)
    TextView tvNv;
    @BindView(R.id.yonghudenglu)
    EditText yonghudenglu;
    @BindView(R.id.next)
    Button next;
    @BindView(R.id.re_nan)
    RelativeLayout reNan;
    @BindView(R.id.re_nv)
    RelativeLayout reNv;
    @BindView(R.id.fanhui)
    TextView fanhui;
    @BindView(R.id.nan1)
    ImageView nan1;
    @BindView(R.id.nv1)
    ImageView nv1;
    private static WeakReference<GeRenActivity> sActivityRef;

    public static void finishActivity() {
        if (sActivityRef != null && sActivityRef.get() != null) {
            sActivityRef.get().finish();
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sActivityRef = new WeakReference<>(this);

        setContentView(R.layout.activity_geren);
        ButterKnife.bind(this);




        Glide.with(GeRenActivity.this).load(R.drawable.nan).asGif().into(nan);


        Glide.with(GeRenActivity.this).load(R.drawable.nv).asGif().into(nv);
    }


    /**
     * 拍摄证件照片
     *
     * @param type 拍摄证件类型
     */
    private void takePhoto(int type) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 0x12);
            return;
        }
        CameraActivity.openCertificateCamera(this, type, "1");

    }

    @OnClick({R.id.fanhui, R.id.next, R.id.re_nan, R.id.re_nv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fanhui:
                finish();
                break;
            case R.id.re_nan:
                nan.setVisibility(View.VISIBLE);
                nan1.setVisibility(View.GONE);
                nv.setVisibility(View.GONE);
                nv1.setVisibility(View.VISIBLE);
                Content.sex="男";
                break;
            case R.id.re_nv:
                nan.setVisibility(View.GONE);
                nan1.setVisibility(View.VISIBLE);
                nv.setVisibility(View.VISIBLE);
                nv1.setVisibility(View.GONE);
                Content.sex="女";
                break;
            case R.id.next:
                if (TextUtils.isEmpty(yonghudenglu.getText().toString())) {
                    Toast.makeText(this, "请输入年龄！", Toast.LENGTH_SHORT).show();
                    return;
                }
                Content.age=yonghudenglu.getText().toString();
                takePhoto(1);

                break;
        }
    }
}
